<template>
  <div class="order-payment">
    <div class="page-header">
      <h1>订单付款</h1>
      <div class="breadcrumb">财务管理 / 订单付款</div>
    </div>

         <div class="search-action-section">
       <div class="search-form">
         <div class="form-item">
           <label>订单类型</label>
           <select v-model="searchForm.orderType">
             <option value="">请选择</option>
             <option value="purchase">采购单</option>
             <option value="return">退货单</option>
           </select>
         </div>
         <div class="form-item">
           <label>订单编号</label>
           <input v-model="searchForm.orderNumber" type="text" placeholder="请输入订单编号" />
         </div>
         <div class="form-item">
           <label>付款状态</label>
           <select v-model="searchForm.paymentStatus">
             <option value="">请选择</option>
             <option value="unpaid">未付款</option>
             <option value="partial">部分付款</option>
             <option value="paid">已付款</option>
           </select>
         </div>
         <div class="form-buttons">
           <button class="btn btn-primary" @click="searchOrders">查询</button>
           <button class="btn btn-secondary" @click="resetSearch">重置</button>
         </div>
       </div>

       <div class="action-buttons">
         <button class="btn btn-primary" @click="showAddModal = true">
           <span class="btn-icon">+</span>
           手动录入订单
         </button>
       </div>
     </div>

         <div class="table-pagination-section">
       <div class="table-container">
         <table class="data-table">
           <thead>
             <tr>
               <th><input type="checkbox" v-model="selectAll" @change="toggleSelectAll" /></th>
               <th>订单类型</th>
               <th>订单编号</th>
               <th>采购/退货日期</th>
               <th>供应商/客户</th>
               <th>负责人</th>
               <th>联系电话</th>
               <th>总金额 (元)</th>
               <th>待付款金额 (元)</th>
               <th>状态</th>
               <th>备注</th>
               <th>创建人</th>
               <th>创建时间</th>
               <th>操作</th>
             </tr>
           </thead>
           <tbody>
                         <tr v-for="order in orderList" :key="order.id" :class="{ 'selected-row': order.selected }" @click="toggleRowSelect(order, $event)">
              <td><input type="checkbox" v-model="order.selected" @click.stop /></td>
               <td>{{ order.orderType }}</td>
               <td>{{ order.orderNumber }}</td>
               <td>{{ order.orderDate }}</td>
               <td>{{ order.supplierName }}</td>
               <td>{{ order.responsiblePerson }}</td>
               <td>{{ order.contactPhone }}</td>
               <td>{{ order.totalAmount }}</td>
               <td>{{ order.pendingAmount }}</td>
                               <td>
                  <span :class="getStatusClass(order.status)">{{ getStatusText(order) }}</span>
                </td>
               <td>{{ order.remark || '-' }}</td>
               <td>{{ order.creator }}</td>
               <td>{{ order.createTime }}</td>
                               <td>
                  <button
                    v-if="order.applicationStatus === 0 && order.paymentStatus !== 2"
                    class="btn btn-small btn-primary"
                    @click="openPaymentModal(order)"
                    :disabled="order.pendingAmount <= 0"
                  >
                    付款申请
                  </button>
                  <span v-else-if="order.applicationStatus === 1" class="status-applied">已申请</span>
                  <span v-else-if="order.applicationStatus === 2" class="status-approving">审批中</span>
                  <span v-else-if="order.applicationStatus === 3" class="status-approved">已审批</span>
                  <span v-else-if="order.applicationStatus === 4 || order.paymentStatus === 2" class="payment-completed">已付款完毕</span>
                  <span v-else class="payment-completed">已付款完毕</span>
                </td>
             </tr>
           </tbody>
         </table>
       </div>

       <div class="pagination">
         <div class="pagination-info">共{{ totalPages }}页/{{ totalItems }}条数据</div>
         <div class="pagination-controls">
           <button class="btn btn-page" :disabled="currentPage === 1" @click="changePage(currentPage - 1)">上一页</button>
           <button v-for="page in visiblePages" :key="page" class="btn btn-page" :class="{ active: page === currentPage }" @click="changePage(page)">{{ page }}</button>
           <button class="btn btn-page" :disabled="currentPage === totalPages" @click="changePage(currentPage + 1)">下一页</button>
         </div>
         <div class="pagination-jump">
           <span>跳至</span>
           <input type="number" v-model="jumpPage" min="1" :max="totalPages" />
           <span>页</span>
           <button class="btn btn-small" @click="jumpToPage">确定</button>
         </div>
       </div>
     </div>

    <!-- 手动录入订单模态框 -->
    <div v-if="showAddModal" class="modal-overlay" @click="showAddModal = false">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>手动录入订单</h3>
          <button class="modal-close" @click="showAddModal = false">&times;</button>
        </div>
        <div class="modal-body">
          <div class="form-row">
            <div class="form-group">
              <label class="required">订单类型</label>
              <select v-model="addOrderForm.orderType" class="form-select">
                <option value="">请选择</option>
                <option value="purchase">采购单</option>
                <option value="return">退货单</option>
              </select>
            </div>
            <div class="form-group">
              <label class="required">订单编号</label>
              <input type="text" v-model="addOrderForm.orderNumber" placeholder="请输入订单编号" class="form-input" />
            </div>
          </div>
          <div class="form-row">
            <div class="form-group">
              <label class="required">采购/退货日期</label>
              <input type="date" v-model="addOrderForm.orderDate" class="form-input" />
            </div>
            <div class="form-group">
              <label class="required">供应商/客户</label>
              <input type="text" v-model="addOrderForm.supplierName" placeholder="请输入供应商/客户名称" class="form-input" />
            </div>
          </div>
          <div class="form-row">
            <div class="form-group">
              <label class="required">负责人</label>
              <input type="text" v-model="addOrderForm.responsiblePerson" placeholder="请输入负责人姓名" class="form-input" />
            </div>
            <div class="form-group">
              <label class="required">联系电话</label>
              <input type="text" v-model="addOrderForm.contactPhone" placeholder="请输入联系电话" class="form-input" />
            </div>
          </div>
          <div class="form-row">
            <div class="form-group">
              <label class="required">总金额 (元)</label>
              <input type="number" v-model="addOrderForm.totalAmount" placeholder="请输入总金额" step="0.01" min="0" class="form-input" />
            </div>
            <div class="form-group">
              <label class="required">待付款金额 (元)</label>
              <input type="number" v-model="addOrderForm.pendingAmount" placeholder="请输入待付款金额" step="0.01" min="0" class="form-input" />
            </div>
          </div>
          <div class="form-group full-width">
            <label>备注</label>
            <textarea v-model="addOrderForm.remark" placeholder="请输入备注信息" rows="3" class="form-textarea"></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button class="btn btn-secondary" @click="showAddModal = false">取消</button>
          <button class="btn btn-primary" @click="submitAddOrder" :disabled="!isAddFormValid">确认添加</button>
        </div>
      </div>
    </div>

    <!-- 付款申请模态框 -->
    <div v-if="showPaymentModal" class="modal-overlay" @click="showPaymentModal = false">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>付款申请</h3>
          <button class="modal-close" @click="showPaymentModal = false">&times;</button>
        </div>
        <div class="modal-body">
          <div class="order-info-section">
            <h4>订单信息</h4>
            <div class="order-info-grid">
              <div class="info-item">
                <label>订单类型：</label>
                <span>{{ selectedOrder?.orderType }}</span>
              </div>
              <div class="info-item">
                <label>订单编号：</label>
                <span>{{ selectedOrder?.orderNumber }}</span>
              </div>
              <div class="info-item">
                <label>采购日期：</label>
                <span>{{ selectedOrder?.orderDate }}</span>
              </div>
              <div class="info-item">
                <label>供应商：</label>
                <span>{{ selectedOrder?.supplierName }}</span>
              </div>
              <div class="info-item">
                <label>负责人：</label>
                <span>{{ selectedOrder?.responsiblePerson }}</span>
              </div>
              <div class="info-item">
                <label>总金额：</label>
                <span>{{ selectedOrder?.totalAmount }}</span>
              </div>
              <div class="info-item">
                <label>未付款金额：</label>
                <span class="highlight-amount">{{ selectedOrder?.pendingAmount }}</span>
              </div>
            </div>
          </div>

          <div class="payment-form-section">
            <h4>付款申请</h4>
            <div class="form-row">
              <div class="form-group">
                <label class="required">付款金额</label>
                <input type="number" v-model="paymentForm.amount" placeholder="请输入付款金额" :max="selectedOrder?.pendingAmount" step="0.01" class="form-input" />
                <small class="form-tip">最大可付款：{{ selectedOrder?.pendingAmount }} 元</small>
              </div>
              <div class="form-group">
                <label class="required">付款方式</label>
                <select v-model="paymentForm.method" class="form-select">
                  <option value="">请选择</option>
                  <option value="bank">银行转账</option>
                  <option value="cash">现金</option>
                  <option value="check">支票</option>
                  <option value="alipay">支付宝</option>
                  <option value="wechat">微信支付</option>
                </select>
              </div>
            </div>
            <div class="form-row">
              <div class="form-group">
                <label class="required">付款日期</label>
                <input type="date" v-model="paymentForm.paymentDate" class="form-input" />
              </div>
              <div class="form-group">
                <label>付款账户</label>
                <select v-model="paymentForm.accountId" class="form-select">
                  <option value="">请选择</option>
                  <option value="ACC001">公司基本账户</option>
                  <option value="ACC002">采购专用账户</option>
                </select>
              </div>
            </div>
            <div class="form-group full-width">
              <label>备注</label>
              <textarea v-model="paymentForm.remark" placeholder="请输入备注信息" rows="3" class="form-textarea"></textarea>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button class="btn btn-secondary" @click="showPaymentModal = false">取消</button>
          <button class="btn btn-primary" @click="submitPayment" :disabled="!isFormValid">确认付款</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, computed, onMounted } from 'vue'
import { apiGet, apiPost } from '../../utils/api.js'

const searchForm = reactive({
  orderType: '',
  orderNumber: '',
  paymentStatus: ''
})

const orderList = ref([])
const selectAll = ref(false)
const currentPage = ref(1)
const totalPages = ref(10)
const totalItems = ref(100)
const jumpPage = ref(1)
const showPaymentModal = ref(false)
const showAddModal = ref(false)
const selectedOrder = ref(null)

const paymentForm = reactive({
  amount: '',
  method: '',
  paymentDate: '',
  accountId: '',
  remark: ''
})

const addOrderForm = reactive({
  orderType: '',
  orderNumber: '',
  orderDate: '',
  supplierName: '',
  responsiblePerson: '',
  contactPhone: '',
  totalAmount: '',
  pendingAmount: '',
  remark: ''
})

const visiblePages = computed(() => {
  const pages = []
  const start = Math.max(1, currentPage.value - 2)
  const end = Math.min(totalPages.value, currentPage.value + 2)
  for (let i = start; i <= end; i++) {
    pages.push(i)
  }
  return pages
})

const isFormValid = computed(() => {
  return paymentForm.amount && paymentForm.method && paymentForm.paymentDate
})

const isAddFormValid = computed(() => {
  return addOrderForm.orderType && addOrderForm.orderNumber && addOrderForm.orderDate &&
         addOrderForm.supplierName && addOrderForm.responsiblePerson && addOrderForm.contactPhone &&
         addOrderForm.totalAmount && addOrderForm.pendingAmount
})

const searchOrders = async () => {

  await loadOrderData()
}

const resetSearch = async () => {
  searchForm.orderType = ''
  searchForm.orderNumber = ''
  searchForm.paymentStatus = ''
  await loadOrderData()
}

const toggleSelectAll = () => {
  orderList.value.forEach(order => {
    order.selected = selectAll.value
  })
}

const toggleRowSelect = (order, event) => {
  const target = event?.target
  if (!target) {
    order.selected = !order.selected
    return
  }
  const tag = target.tagName?.toLowerCase()
  if (tag === 'input' || tag === 'button' || tag === 'a') return
  if (target.closest && target.closest('button')) return
  order.selected = !order.selected
}

const changePage = async (page) => {
  currentPage.value = page
  await loadOrderData()
}

const jumpToPage = async () => {
  if (jumpPage.value >= 1 && jumpPage.value <= totalPages.value) {
    currentPage.value = jumpPage.value
    await loadOrderData()
  }
}

const getStatusClass = (status) => {
  switch (status) {
    case 'unpaid': return 'status-unpaid'
    case 'partial': return 'status-partial'
    case 'paid': return 'status-paid'
    default: return ''
  }
}

const getStatusText = (order) => {
  // 根据申请状态和付款状态显示文本
  if (order.applicationStatus === 1) {
    return '已申请'
  } else if (order.applicationStatus === 2) {
    return '审批中'
  } else if (order.applicationStatus === 3) {
    return '已审批'
  } else if (order.applicationStatus === 4) {
    return '已付款'
  } else {
    // 根据付款状态显示
    switch (order.paymentStatus) {
      case 0: return '未付款'
      case 1: return '部分付款'
      case 2: return '已付款'
      default: return '未付款'
    }
  }
}

const openPaymentModal = (order) => {
  selectedOrder.value = order
  paymentForm.amount = order.pendingAmount
  paymentForm.method = ''
  paymentForm.paymentDate = new Date().toISOString().split('T')[0]
  paymentForm.accountId = ''
  paymentForm.remark = ''
  showPaymentModal.value = true
}

const submitPayment = async () => {
  try {
    const requestData = {
      orderId: selectedOrder.value.id,
      orderNumber: selectedOrder.value.orderNumber,
      amount: parseFloat(paymentForm.amount),
      paymentMethod: paymentForm.method,
      paymentDate: paymentForm.paymentDate,
      remark: paymentForm.remark,
      accountId: paymentForm.accountId,
      accountName: paymentForm.accountId === 'ACC001' ? '公司基本账户' : '采购专用账户',
      applicant: 'admin' // 添加申请人信息
    }

    const result = await apiPost('/finance/order-payments/apply', requestData)

    if (result.success) {
      alert(result.message || '付款申请提交成功')
      showPaymentModal.value = false
      paymentForm.amount = ''
      paymentForm.method = ''
      paymentForm.paymentDate = ''
      paymentForm.accountId = ''
      paymentForm.remark = ''
      selectedOrder.value = null
      await loadOrderData()
    } else {
      alert(result.message || '付款申请提交失败')
    }
  } catch (error) {
    console.error('提交付款申请时出错:', error)
    alert('提交付款申请时出错')
  }
}

const submitAddOrder = async () => {
  try {
    // 准备提交给后端的数据
    const orderData = {
      orderType: addOrderForm.orderType === 'purchase' ? '采购单' : '退货单',
      orderNumber: addOrderForm.orderNumber,
      orderDate: addOrderForm.orderDate,
      supplierName: addOrderForm.supplierName,
      responsiblePerson: addOrderForm.responsiblePerson,
      contactPhone: addOrderForm.contactPhone,
      totalAmount: addOrderForm.totalAmount,
      pendingAmount: addOrderForm.pendingAmount,
      remark: addOrderForm.remark,
      creator: 'admin'
    }

    // 调用后端API创建订单
    const result = await apiPost('/finance/order-payments', orderData)

    if (result.success) {
      // 创建成功，重新加载数据
      await loadOrderData()

      // 重置表单
      resetAddForm()
      showAddModal.value = false

      alert('订单添加成功！')
    } else {
      alert(result.message || '订单添加失败')
    }
  } catch (error) {
    console.error('添加订单时出错:', error)
    alert('添加订单时出错')
  }
}

const resetAddForm = () => {
  addOrderForm.orderType = ''
  addOrderForm.orderNumber = ''
  addOrderForm.orderDate = ''
  addOrderForm.supplierName = ''
  addOrderForm.responsiblePerson = ''
  addOrderForm.contactPhone = ''
  addOrderForm.totalAmount = ''
  addOrderForm.pendingAmount = ''
  addOrderForm.remark = ''
}

const loadOrderData = async () => {
  try {
    const params = new URLSearchParams({
      page: currentPage.value,
      size: 10,
      ...(searchForm.orderType && { orderType: searchForm.orderType }),
      ...(searchForm.orderNumber && { orderNumber: searchForm.orderNumber }),
      ...(searchForm.paymentStatus && { paymentStatus: searchForm.paymentStatus })
    })

    const data = await apiGet(`/finance/order-payments?${params}`)

    if (data.content) {
      orderList.value = data.content.map(order => ({
        ...order,
        selected: false,
        // 确保字段映射正确
        supplierName: order.supplierCustomerName || order.supplierName,
        responsiblePerson: order.contactPerson || order.responsiblePerson,
        creator: order.creatorName || order.creator,
        // 设置默认值
        applicationStatus: order.applicationStatus || 0,
        paymentStatus: order.paymentStatus || 0
      }))
      totalPages.value = data.totalPages
      totalItems.value = data.totalElements
    } else {
      orderList.value = data.map(order => ({
        ...order,
        selected: false,
        supplierName: order.supplierCustomerName || order.supplierName,
        responsiblePerson: order.contactPerson || order.responsiblePerson,
        creator: order.creatorName || order.creator,
        applicationStatus: order.applicationStatus || 0,
        paymentStatus: order.paymentStatus || 0
      }))
      totalPages.value = data.totalPages || 1
      totalItems.value = data.totalElements || data.length
    }
  } catch (error) {
    console.error('加载订单数据时出错:', error)
    orderList.value = Array.from({ length: 13 }, (_, index) => ({
      id: index + 1,
      selected: false,
      orderType: '采购单',
      orderNumber: 'CG001',
      orderDate: '2023-01-03',
      supplierName: 'XXX有限公司',
      responsiblePerson: '夏油杰',
      contactPhone: '13333333333',
      totalAmount: '5000.00',
      pendingAmount: '5000.00',
      status: 'partial',
      statusText: '部分付款',
      remark: '',
      creator: '夏油杰',
      createTime: '2024-08-23',
      applicationStatus: 0,
      paymentStatus: 1
    }))
  }
}

onMounted(() => {
  loadOrderData()
})
</script>

<style scoped>
.order-payment {
  padding: 20px;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  position: relative;
}

.order-payment::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="75" cy="75" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="50" cy="10" r="0.5" fill="rgba(255,255,255,0.1)"/><circle cx="10" cy="60" r="0.5" fill="rgba(255,255,255,0.1)"/><circle cx="90" cy="40" r="0.5" fill="rgba(255,255,255,0.1)"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
  opacity: 0.3;
  pointer-events: none;
}

.page-header {
  margin-bottom: 30px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 25px 30px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
  position: relative;
  overflow: hidden;
}

.page-header::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(180deg); }
}

.page-header h1 {
  margin: 0 0 10px 0;
  font-size: 32px;
  color: white;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  position: relative;
  z-index: 1;
}

.breadcrumb {
  color: rgba(255, 255, 255, 0.9);
  font-size: 16px;
  font-weight: 500;
  position: relative;
  z-index: 1;
}

.search-action-section {
  background: rgba(255, 255, 255, 0.95);
  padding: 25px 30px;
  border-radius: 16px;
  margin-bottom: 25px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 20px;
}

.search-action-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
}

.search-form {
  display: flex;
  gap: 20px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.form-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-item label {
  font-weight: 500;
  color: #333;
  font-size: 14px;
}

.form-item input,
.form-item select {
  padding: 12px 16px;
  border: 2px solid #e1e5e9;
  border-radius: 12px;
  font-size: 14px;
  min-width: 180px;
  background: rgba(255, 255, 255, 0.9);
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.form-item input:focus,
.form-item select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.2);
}

.form-item input:hover,
.form-item select:hover {
  border-color: #adb5bd;
  transform: translateY(-1px);
}

.form-buttons {
  display: flex;
  gap: 10px;
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  margin-right: 8px;
  font-weight: bold;
  font-size: 16px;
}

.table-pagination-section {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
  margin-bottom: 25px;
}

.table-pagination-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #4facfe 0%, #00f2fe 50%, #43e97b 100%);
}

.table-container {
  overflow-x: auto;
  padding: 20px 20px 0 20px;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  border: none;
  backdrop-filter: none;
  position: static;
  overflow: visible;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 12px 8px;
  text-align: left;
  border-bottom: 1px solid #eee;
}

.data-table th {
  background: #f8f9fa;
  font-weight: 600;
  color: #495057;
  padding: 16px 12px;
  border: none;
  position: relative;
  border-bottom: 2px solid #e9ecef;
}

.data-table tbody tr {
  transition: all 0.3s ease;
  border-bottom: 1px solid rgba(225, 229, 233, 0.5);
}

.data-table tbody tr:hover {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
}

.data-table tbody tr.selected-row {
  background: linear-gradient(135deg, rgba(40, 167, 69, 0.08) 0%, rgba(32, 201, 151, 0.08) 100%);
  border-left: 4px solid #20c997;
  box-shadow: inset 0 0 0 1px rgba(32, 201, 151, 0.25);
}

.data-table tbody tr:last-child {
  border-bottom: none;
}

.status-unpaid {
  color: #dc3545;
  font-weight: 600;
  background: rgba(220, 53, 69, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(220, 53, 69, 0.3);
  display: inline-block;
}

.status-partial {
  color: #ffc107;
  font-weight: 600;
  background: rgba(255, 193, 7, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255, 193, 7, 0.3);
  display: inline-block;
}

.status-paid {
  color: #28a745;
  font-weight: 600;
  background: rgba(40, 167, 69, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(40, 167, 69, 0.3);
  display: inline-block;
}

.payment-completed {
  color: #28a745;
  font-weight: 600;
  font-style: italic;
  background: rgba(40, 167, 69, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(40, 167, 69, 0.3);
  display: inline-block;
}

.status-applied {
  color: #17a2b8;
  font-weight: 600;
  background: rgba(23, 162, 184, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(23, 162, 184, 0.3);
  display: inline-block;
}

.status-approving {
  color: #fd7e14;
  font-weight: 600;
  background: rgba(253, 126, 20, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(253, 126, 20, 0.3);
  display: inline-block;
}

.status-approved {
  color: #20c997;
  font-weight: 600;
  background: rgba(32, 201, 151, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(32, 201, 151, 0.3);
  display: inline-block;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 20px 20px;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  border: none;
  backdrop-filter: none;
  position: static;
  overflow: visible;
  border-top: 1px solid #e9ecef;
}

.pagination-info {
  color: #666;
  font-size: 14px;
}

.pagination-controls {
  display: flex;
  gap: 5px;
}

.pagination-jump {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-jump input {
  width: 80px;
  padding: 8px 12px;
  border: 2px solid #e1e5e9;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.pagination-jump input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* 基础按钮样式已在上方优化部分定义 */

.btn-page {
  background: rgba(255, 255, 255, 0.9);
  color: #333;
  border: 2px solid #e1e5e9;
  border-radius: 12px;
  padding: 10px 16px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.btn-page:hover {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: transparent;
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3);
}

.btn-page.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
}

/* 模态框样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  border: 1px solid #e1e5e9;
  position: relative;
}

.modal-header {
  padding: 18px 20px 16px 20px;
  border-bottom: 1px solid #e1e5e9;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
  color: white !important;
  border-radius: 12px 12px 0 0;
}

.modal-header h3 {
  margin: 0;
  color: white;
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: rgba(255, 255, 255, 0.2) !important;
  border: none !important;
  font-size: 16px !important;
  cursor: pointer !important;
  color: white !important;
  width: 24px !important;
  height: 24px !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.2s !important;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.modal-body {
  padding: 16px 20px;
  max-height: calc(80vh - 120px);
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  box-sizing: border-box;
}

.modal-footer {
  padding: 14px 20px 18px 20px;
  border-top: 1px solid #e1e5e9;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: #f8f9fa;
  border-radius: 0 0 12px 12px;
}

.order-info-section,
.payment-form-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e1e5e9;
}

.order-info-section:last-child,
.payment-form-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.order-info-section h4,
.payment-form-section h4 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 14px;
  color: #2c3e50;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.order-info-section h4::before,
.payment-form-section h4::before {
  content: '';
  width: 3px;
  height: 14px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  margin-right: 8px;
  border-radius: 2px;
}

.order-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.info-item {
  display: flex;
  align-items: center;
  padding: 8px;
  background: #f8f9fa;
  border-radius: 6px;
  border-left: 3px solid #667eea;
}

.info-item label {
  font-weight: 500;
  color: #495057;
  margin-right: 8px;
  min-width: 70px;
  font-size: 12px;
}

.info-item span {
  font-weight: 600;
  color: #2c3e50;
  font-size: 12px;
}

.highlight-amount {
  color: #e74c3c;
  font-weight: 700;
  font-size: 12px;
}

/* 表单行布局 */
.form-row {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 16px !important;
  margin-bottom: 16px !important;
}

.form-group {
  margin-bottom: 16px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  color: #2c3e50;
  font-size: 12px;
}

.form-group label.required::after {
  content: ' *';
  color: #e74c3c;
  font-weight: 700;
}

.form-input,
.form-select,
.form-textarea {
  width: 100% !important;
  padding: 8px 12px !important;
  border: 2px solid #e1e5e9 !important;
  border-radius: 6px !important;
  font-size: 12px !important;
  transition: all 0.3s ease !important;
  background: #ffffff !important;
  box-sizing: border-box !important;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
  transform: translateY(-1px);
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
  border-color: #adb5bd;
}

.form-textarea {
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

.form-tip {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  color: #6c757d;
  font-style: italic;
}

/* 按钮样式优化 */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
  color: white !important;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4) !important;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: linear-gradient(135deg, #6c757d 0%, #495057 100%) !important;
  color: white !important;
  box-shadow: 0 4px 15px rgba(108, 117, 125, 0.4) !important;
}

.btn-secondary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(108, 117, 125, 0.6);
}

.btn-small {
  padding: 4px 8px;
  font-size: 10px;
}

/* 确保弹框内容不溢出 */
.modal-content * {
  box-sizing: border-box;
}

.form-group {
  min-width: 0;
  overflow: hidden;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .form-row {
    grid-template-columns: 1fr !important;
  }

  .order-info-grid {
    grid-template-columns: 1fr;
  }

  .modal-content {
    width: 95%;
    margin: 20px;
    max-width: none;
  }

  .modal-body {
    padding: 12px;
  }

  .search-form {
    flex-direction: column;
    align-items: stretch;
  }
}
</style>
